package com.zdd.common;

/**
 * @Description 简单工厂模式的通用写法
 * @author carl
 */
public class Client {

    public static void main(String[] args){
        IProduct product = new SimpleFactory().makeProduct(1);
        product.doSomething();
    }

    // 抽象产品
    public interface IProduct{
        void doSomething();
    }

    // 具体产品A
    static class ProductA implements IProduct{

        @Override
        public void doSomething() {
            System.out.println("this is ProductA");
        }
    }

    // 具体产品B
    static class ProductB  implements IProduct{

        @Override
        public void doSomething() {
            System.out.println("this is ProductB");
        }
    }

    static class ProductC implements IProduct{

        @Override
        public void doSomething() {
            System.out.println("this is ProductC");
        }
    }

    final class Const{
        static final int PRODUCT_A = 0;
        static final int PRODUCT_B = 1;
        static final int PRODUCT_C = 2;
    }

    static class SimpleFactory{
        public static IProduct makeProduct(int kind){
            switch (kind){
                case Const.PRODUCT_A:
                    return new ProductA();
                case Const.PRODUCT_B:
                    return new ProductB();
                case Const.PRODUCT_C:
                    return new ProductC();
            }
            return null;
        }
    }
}
